﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using MySql.Data.MySqlClient;
using System.Data;
using l1cs.server.utils;

namespace l1cs.server.datatables
{
    public class ResolventTable
    {
        private static Logger _log = Logger.getLogger( typeof( ResolventTable ).FullName );

        private static ResolventTable _instance;

        private Dictionary<int, int> _resolvent = new Dictionary<int, int>();

        public static ResolventTable getInstance()
        {
            if ( _instance == null )
            {
                _instance = new ResolventTable();
            }
            return _instance;
        }

        private ResolventTable()
        {/*TTOK*/
            String sqlstr = "SELECT * FROM resolvent";
            using ( MySqlWrapper wrapper = new MySqlWrapper() )
            {
                foreach ( DataRow item in wrapper.GetDataTable( sqlstr ).Rows )
                {
                    int itemId = SqlUtils.toInt( item["item_id"] );
                    int crystalCount = SqlUtils.toInt( item["crystal_count"] );

                    _resolvent[itemId] = crystalCount;
                }
            }
            _log.config( "resolvent " + _resolvent.Count );
        }

        public int getCrystalCount( int itemId )
        {/*TTOK*/
            int crystalCount = 0;
            if ( _resolvent.ContainsKey( itemId ) )
            {
                crystalCount = _resolvent[itemId];
            }
            return crystalCount;
        }
    }
}
